﻿<UserControl x:Class="ScrumFactory.Backlog.BacklogItemDetail"
             x:Name="thisView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             
             xmlns:props="clr-namespace:ScrumFactory.Backlog.Properties"
             
                 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.InputBindings>
        <KeyBinding Key="Escape" Command="{Binding CloseWindowCommand}" CommandParameter="{Binding ElementName=thisView}"/>
    </UserControl.InputBindings>
    
    <UserControl.Resources>        
        <DataTemplate x:Key="StatusItemDataTemplate">
            <StackPanel Orientation="Horizontal">
                <Image DataContext="{Binding}" Style="{StaticResource BacklogItemStatusImage}" Width="24" Height="24" Stretch="Uniform" />
                <TextBlock Margin="5,0,0,0" Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
   
    
    
     <Grid                      
            Margin="10,0,5,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="50"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0">
            <TextBlock Margin="0,10,0,0" Style="{StaticResource PanelMainTitle}" Text="{Binding Item.BacklogItemNumber, StringFormat={x:Static props:Resources.Backlog_Item_0}}"/>                
            </StackPanel>

         
         
        <Border Grid.Row="1"
                        Style="{StaticResource ContentPanelBorder}"
                        Margin="0,5,0,0"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            
            <Grid VerticalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <ToolBar                                        
                    Grid.Row="0">            
                    <MenuItem                                
                        Header="{x:Static props:Resources.Close}" Command="{Binding CloseWindowCommand}" CommandParameter="{Binding ElementName=thisView}">
                        <MenuItem.Icon>
                            <Image Source="/Images/ToolBar/Close_window.png" Width="32" Height="32" Stretch="Uniform"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ToolBar>

                <Grid                                                
                    Grid.Row="1" VerticalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="160" />
                        <ColumnDefinition x:Name="dataColumn" Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>                        
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <TextBlock                          
                        Grid.Column="0" Grid.Row="0"                        
                        VerticalAlignment="Top"
                        TextWrapping="Wrap"
                        Style="{StaticResource LabelTextBlock}">
                        <TextBlock                                                  
                            Text="{Binding Item.SprintNumber, StringFormat={x:Static props:Resources.Hours_to_finish}}"
                            VerticalAlignment="Top" TextWrapping="Wrap"
                            Style="{StaticResource LabelTextBlock}"/>
                        <LineBreak/>
                        <TextBlock             
                            Foreground="{StaticResource SubTextBrush}"                            
                            FontSize="{StaticResource TinyFontSize}"
                            TextWrapping="Wrap"
                            Text="{Binding Item.PlanningNumber, StringFormat={x:Static props:Resources.last_planned_at}}">
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource LabelTextBlock}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Item.PlanningNumber}" Value="0">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                            </TextBlock>
                    </TextBlock>

                    <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
                        <ItemsControl                                                       
                        ItemsSource="{Binding PlannedHours}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Vertical" Width="60" >
                                        <TextBox
                                        IsEnabled="{Binding ElementName=thisView, Path=DataContext.CanEditHours}"
                                        FontSize="{StaticResource ReallyBigFontSize}"
                                        HorizontalContentAlignment="Right"
                                        HorizontalAlignment="Stretch"
                                        Text="{Binding Hours, StringFormat='{}0.#', UpdateSourceTrigger=PropertyChanged}"
                                        FontWeight="Bold"/>
                                        <TextBlock
                                        Style="{StaticResource LabelTextBlock}" FontSize="{StaticResource TinyFontSize}"
                                        Text="{Binding Role.RoleName}"
                                        TextWrapping="Wrap"
                                        HorizontalAlignment="Center"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                        <Border Margin="10,0,0,0">
                            <StackPanel Orientation="Horizontal" >
                                <TextBlock
                                    Foreground="Black"
                                    Text="{Binding Item.SprintNumber, StringFormat={x:Static props:Resources.Can_not_change_item_hours}}"/>
                                <Button
                                    Margin="10,0,0,0" Width="100" Height="50"
                                    HorizontalContentAlignment="Center"
                                    Command="{Binding ReplanToCurrentSprintCommand}"
                                    Content="{x:Static props:Resources.Replan_to_current_sprint}"/>
                            </StackPanel>
                            <Border.Style>
                                <Style TargetType="{x:Type Border}" BasedOn="{StaticResource AlertBorder}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding CanEditHours}" Value="True">
                                            <Setter Property="Border.Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                        </Border>
                    </StackPanel>
                   
                    
                    
                        
                    <TextBlock                          
                        Grid.Column="0" Grid.Row="1"
                        Text="{x:Static props:Resources.Status}"                        
                        Style="{StaticResource LabelTextBlock}"/>
                    <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal">
                        <ComboBox                                                    
                            HorizontalAlignment="Left"                        
                            ItemTemplate="{StaticResource StatusItemDataTemplate}"
                            SelectedValue="{Binding ItemStatus, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:BacklogItemStatus},                        UpdateSourceTrigger=PropertyChanged}"                        
                            Width="220"
                            ItemsSource="{Binding Source={StaticResource BacklogItemStatusList}}"/>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{x:Static props:Resources.started_at}" Style="{StaticResource LabelTextBlock}"/>
                            <TextBox Text="{Binding Item.StartedAt, StringFormat='{}{0:d}', UpdateSourceTrigger=PropertyChanged}" Width="100"/>
                            <TextBlock Text="{x:Static props:Resources.finished_at}" Style="{StaticResource LabelTextBlock}"/>
                            <TextBox Text="{Binding Item.FinishedAt, StringFormat='{}{0:d}', UpdateSourceTrigger=PropertyChanged}" Width="100"/>
                            <StackPanel.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Item.Status}" Value="0">
                                            <Setter Property="StackPanel.Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </StackPanel.Style>
                        </StackPanel>
                    </StackPanel>

                    <TextBlock                                       
                        Grid.Column="0" Grid.Row="2"
                        Text="{x:Static props:Resources.Item}"
                        Style="{StaticResource LabelTextBlock}"/>
                    <TextBox                                                                                         
                        Grid.Column="1"  Grid.Row="2"
                        HorizontalAlignment="Stretch"                        
                        Text="{Binding Item.Name, UpdateSourceTrigger=PropertyChanged}"/>                    
                    <TextBlock Grid.Column="0"  Grid.Row="3"
                               Text="{x:Static props:Resources.Description}"                               
                               Style="{StaticResource LabelTextBlock}" VerticalAlignment="Top"/>                    
                    <TextBox Grid.Column="1"  Grid.Row="3"
                             Text="{Binding Item.Description, UpdateSourceTrigger=PropertyChanged}"                             
                             AcceptsReturn="True" TextWrapping="Wrap"
                             HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

                
            </Grid>




            </Grid>


       

        </Border>



        </Grid>
</UserControl>
